<script>
export default {
  onLaunch: function() {
    console.log('App Launch');
    // 检查登录状态
    this.checkLogin();
  },
  onShow: function() {
    console.log('App Show');
  },
  onHide: function() {
    console.log('App Hide');
  },
  methods: {
    checkLogin() {
      const token = uni.getStorageSync('token');
      if (!token) {
        // 如果没有登录，跳转到登录页
        uni.navigateTo({
          url: '/pages/login/login'
        });
      } else {
        // 验证token是否有效
        this.$store.dispatch('user/validateToken').catch(() => {
          uni.navigateTo({
            url: '/pages/login/login'
          });
        });
      }
    }
  }
};
</script>

<style lang="scss">
/* 全局样式 */

page {
  background-color: #f8f8f8;
  font-size: 28rpx;
  color: #333;
  font-family: Helvetica Neue, Helvetica, sans-serif;
}

.container {
  padding: 20rpx;
}

.form-group {
  margin-bottom: 30rpx;
}

.form-label {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 10rpx;
}

.btn-primary {
  background-color: #3c8dbc;
  color: #fff;
}

.btn-danger {
  background-color: #dd524d;
  color: #fff;
}

.btn-success {
  background-color: #4cd964;
  color: #fff;
}

.text-center {
  text-align: center;
}

.text-primary {
  color: #3c8dbc;
}

.text-danger {
  color: #dd524d;
}

.text-success {
  color: #4cd964;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.justify-between {
  justify-content: space-between;
}

.justify-center {
  justify-content: center;
}

.align-center {
  align-items: center;
}

.card {
  background-color: #fff;
  border-radius: 10rpx;
  padding: 20rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.divider {
  height: 1rpx;
  background-color: #eee;
  margin: 20rpx 0;
}
</style>